from tqdm import tqdm
from agent.agent import Agent
from collections import Counter

def get_keywords(questions, enable_bar=True):
    keywords = []
    agent = Agent(__get_system_content())
    for question in tqdm(questions, desc='提取关键词', unit='问题', disable=not enable_bar):
        keywords.append(agent.ask(question))
    return dict(sorted(Counter(keywords).items(), key=lambda item: item[1], reverse=True))

def __get_system_content():
    return '''You are a smart keyword extractor, and your task is to extract what the user said into one keyword.
              Please remember: do not give any explanation to the user, just answer the keyword!'''
